package com.benyi.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class ObjectUtil {
	
	/**
	   *  将 from 对象中不为 null 的值复制到 to 对象
	 * @param from
	 * @param to
	 * @param cls
	 * @return
	 */
	public static <T> T copyFrom(T from,T to,Class cls) throws Exception  {
		if(from==null || to==null) {
			return to;
		}
		Field []fs=cls.getDeclaredFields();
		Field f;
		for(int i=0;i<fs.length;i++) {
			f=fs[i]; 
			if(Modifier.isStatic(f.getModifiers())) {
				continue;
			} 
			f.setAccessible(true);
			Object v=f.get(from);
			if(v==null) {
				continue;
			} 
			f.set(to, v); 
		}
		return to;
	}
	 
	
	public static void main(String []args) throws Exception  {
		 int a=0; 
	}
}
